package com.micro.commonlibrary.tools;

import android.app.Activity;
import android.support.design.widget.Snackbar;
import android.view.View;
import android.widget.TextView;

import com.micro.commonlibrary.R;

public class SnackBarUtils {
    public static void showShortSnack(View view, String text) {
        setSnackBarTheme(Snackbar.make(view, text, Snackbar.LENGTH_SHORT)).show();
    }

    public static void showLongSnack(View view, String text) {
        setSnackBarTheme(Snackbar.make(view, text, Snackbar.LENGTH_LONG)).show();
    }

    public static void showClickSnack(View view, String text, String clickText, View.OnClickListener onClickListener) {
        setSnackBarTheme(Snackbar.make(view, text, Snackbar.LENGTH_LONG).setAction(clickText, onClickListener)).show();
    }

    public static void showShortSnack(Activity activity, String text) {
        setSnackBarTheme(Snackbar.make(activity.getWindow().getDecorView(), text, Snackbar.LENGTH_SHORT)).show();
    }

    public static void showLongSnack(Activity activity, String text) {
        setSnackBarTheme(Snackbar.make(activity.getWindow().getDecorView(), text, Snackbar.LENGTH_LONG)).show();
    }

    public static void showClickSnack(Activity activity, String text, String clickText, View.OnClickListener onClickListener) {
        setSnackBarTheme(Snackbar.make(activity.getWindow().getDecorView(), text, Snackbar.LENGTH_LONG).setAction(clickText, onClickListener)).show();
    }
//  这里定制眼熟
    private static Snackbar setSnackBarTheme(Snackbar snackbar) {
        View view = snackbar.getView();
        int snackbar_text = android.support.design.R.id.snackbar_text;
        TextView viewById = view.findViewById(snackbar_text);
        viewById.setTextColor(UiTools.getColor(R.color.colorWhite));
        return snackbar;
    }
}
